<?php

use yii\db\Migration;

class m171124_090640_alter_goods extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->addColumn('{{%goods}}', 'class_hour', $this->smallInteger(2)->defaultValue(1)->comment('课时数'));
            $this->addColumn('{{%class_manage_attribute}}', 'class_hour', $this->smallInteger(2)->defaultValue(1)->comment('课时数'));
            $this->addColumn('{{%arrangement}}', 'class_hour', $this->smallInteger(2)->defaultValue(1)->comment('课时数'));
        }

    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropColumn('{{%goods}}', 'class_hour');
            $this->dropColumn('{{%class_manage_attribute}}', 'class_hour');
            $this->dropColumn('{{%arrangement}}', 'class_hour');
        }
    }
}
